package odgs.transaction;

import odgs.Contents;
import odgs.SelectGridNode;
import odgs.Transaction;
import odgs.listener.FileListener;
import odgs.manager.TransactionManager;
import odgs.message.Message;

public class ContentsAddTransaction extends Transaction implements FileListener
{
	private Contents source;
	private String localPath;
	private long totalSize;
	private long sendedSize;
	transient private int speed;
	transient private TransactionManager manager; 
	
	public ContentsAddTransaction(long id)
	{
		super(id);
	}
	
	public void setTotalSize(long size)
	{
		this.totalSize = size;
	}

	@Override
	public String getName()
	{
		return "ContentsAddTransaction";
	}

	public void setSource(Contents source)
	{
		this.source = source;
		this.totalSize = source.getSize();
	}

	public Contents getSource()
	{
		return source;
	}

	public long getTotalSendSize()
	{
		return totalSize;
	}

	@Override
	public boolean isFileTrans()
	{
		return true;
	}
	
	@Override
	public String toString()
	{
		return "Add Contents : "  + source.getName();
	}

	public void setLocalPath(String path)
	{
		localPath = path;
	}
	
	public String getLocalPath()
	{
		return localPath;
	}

	public void end(long id, String name)
	{
		if(totalSize <= sendedSize)
		{
			manager.addedContents(this);
		}
	}
	
	public void start(long id, String name){}

	public void sendedSize(long sendedSize, long size)
	{
		this.sendedSize += size;
		this.speed += size;
	}

	public void setZero()
	{
		speed = 0;
	}

	public long getSpeed()
	{
		return speed;
	}

	public long getSendedSize()
	{
		return sendedSize;
	}

	public long getTotalSize()
	{
		return totalSize;
	}

	public void setTransactionManager(TransactionManager transactionManager) 
	{
		manager = transactionManager;
	}
}